<?php

use yii\helpers\Html;
use yii\helpers\Url;
use backend\widgets\GridView;
use yii\widgets\Breadcrumbs;
use backend\models\User;
use backend\models\service\AdminService as Admin;
$this->title = '充值列表';
?>

<div class="RightCenter clear">
    <div class="RightTime">
        <div class="Time">
            <h3>充值列表</h3>

            <div class="input-prepend input-group right_Time">
                <span class="add-on input-group-addon Read_IN"></span>
                <input type="text" readonly  name="birthday" id="reservation" class="form-control form-controlCLOC"/>
                <b class="caret"></b>
            </div>

        </div>
    </div>

    <div class="Read_date" style="margin-top:20px;margin-bottom: 5px;height:60px;">
        <ul>
            <li class="Read_LisJ ">
                <div class="SX clear Read_CZlB">筛选:
                    <select id="type">
                        <option value="">全部充值类型</option>
                        <option <?php echo $select['type'] == 1 ? 'selected="selected"' : '';?> value="1">支付宝</option>
                        <option <?php echo $select['type'] == 2 ? 'selected="selected"' : '';?> value="2">微信</option>
                        <option <?php echo $select['type'] == 3 ? 'selected="selected"' : '';?> value="3">银联</option>
                        <option <?php echo $select['type'] == 4 ? 'selected="selected"' : '';?> value="4">其他</option>
                    </select>

                    <select id="status">
                        <option value="">全部充值状态</option>
                        <option <?php echo $select['status'] == '1' ? 'selected="selected"' : '';?> value="1">成功</option>
                        <option <?php echo $select['status'] == '0' ? 'selected="selected"' : '';?> value="0">失败</option>
                    </select>
                    <button type="button" class="btn btn-primary SS">筛选</button>
                    <button type="button" class="btn btn-primary czS">重置</button>
                </div>
            </li>
        </ul>
    </div>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'id' => 'grid',
        'columns' => [
            [
                'attribute' => 'id',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '充值编号',
                'headerOptions' => ['width' => 10],
            ],
            [
                'attribute' => 'pay_money',
                'label' => '充值金额（元）',
                'headerOptions' => ['width' => 30],
            ],
            [
                'attribute' => 'pay_time',
                'label' => '充值时间',
                'headerOptions' => ['width' => 80],
            ],
            [
                'attribute' => 'pay_type',
                'label' => '充值类型',
                'headerOptions' => ['width' => 80],
                'value' => function($data) {
            switch ($data->pay_type) {
                case 1:
                    return '支付宝';
                case 2:
                    return '微信';
                case 3:
                    return '银联';
                case 4:
                    return '其他';
            }
        }
            ],
            [
//                'attribute' => 'create_time',
                'label' => '昵称账号',
                'headerOptions' => ['width' => 80],
                'value' => function($data) {
            $model = new User();
            $res = $model->getUserInfo($data->user_id);
            return $res['user_nickname'];
        }
            ],
            [
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '注册来源',
                'headerOptions' => ['width' => 80],
                'value' => function($data) {
            $model = new User();
            $res = $model->getUserInfo($data->user_id);
            $channel_id = $res['channel_id'];
            $partner_id = $res['partner_id'];
            $admin = new Admin();
            $cInfos = $admin->getInfoDatas($channel_id);
            $pInfos = $admin->getInfoDatas($partner_id);
            return $cInfos['username'] . "</br>" . $pInfos['username'];
        }
            ],
            [
                'attribute' => 'status',
                'label' => '充值状态',
                'headerOptions' => ['width' => 80],
                'value' => function($data) {
            switch ($data->status) {
                case 0:
                    return '失败';
                case 1:
                    return '成功';
            }
        }
            ],
        ],
    ]);
    ?>
</div>
<script>
    
    var myDate = new Date(); //获取今天日期
    var myYear = myDate.getFullYear() //获取年份
    myDate.setDate(myDate.getDate() - 7);
    var dateArray = [];
    var dateTemp;
    var flag = 1;
    for (var i = 0; i < 7; i++) {
        dateTemp = (myDate.getMonth() + 1) + "-" + myDate.getDate();
        dateArray.push(dateTemp);
        myDate.setDate(myDate.getDate() + flag);
    }
    var Start = myYear + "-" + dateArray[6]
    var S = "<?php echo isset($select['start']) && $select['start'] != '' ? date('Y-m-d',strtotime($select['start'])) : '';?>";
    var E = "<?php echo isset($select['end']) && $select['end'] != '' ? date('Y-m-d',strtotime($select['end'])) : '';?>";
    if(S == ''){
        $("#reservation").val(Start + " " + "-" + " " + Start)
    }else{
        $("#reservation").val(S + " " + "-" + " " + E)
    }
    var s = '';
    var e = '';
    $('#reservation').daterangepicker(null, function (start, end, label) {
        s = moment(start).format("YYYY-MM-DD HH:mm:ss");
        e = moment(end).format("YYYY-MM-DD HH:mm:ss");
        var type = $("#type").val();
        var status = $("#status").val();
        $("#reservation").val(S + " " + "-" + " " + E)
        location.href="/bill/index?Bill[pay_type]="+type+"&Bill[status]="+status+"&Bill[start]="+s+"&Bill[end]="+e
    });
    
    $(".SS").click(function(){
        var type = $("#type").val();
        var status = $("#status").val();
        location.href="/bill/index?Bill[pay_type]="+type+"&Bill[status]="+status+"&Bill[start]="+S+"&Bill[end]="+E
    });
    
    $(".czS").click(function(){
        location.href="/bill/index"
    });
</script>